package com.zwh.se.io.nio.buffer;

import java.nio.ByteBuffer;

/**
 * @author zwh
 * ByteBuffer 支持类型化的 put 和 get，put 放入的是什么数据类型，get 就应该使用相应的数据类型来取出，否则可能有 BufferUnderflowException 异常
 *
 */
public class BufferDemo02 {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);

        byteBuffer.putInt(1);
        byteBuffer.putChar('2');
        byteBuffer.putShort((short) 3);
        byteBuffer.putLong(4L);

        byteBuffer.flip();

        System.out.println(byteBuffer.getInt());
        System.out.println(byteBuffer.getChar());
        System.out.println(byteBuffer.getLong());
        System.out.println(byteBuffer.getLong());

    }
}
